//不能使用sort，会超时
#include<stdio.h>
#include<iostream>
#include<string.h>
#include <algorithm>
using namespace std;
struct candidate
{
	float money;
	char name[65];
};
int main()
{
	int n,k, i, j, cou = 0;//cou~counter
	struct candidate ca[11], temp, x;
	while (cin >> n>>k)
	{
		if (cou)cout << endl;
		cou++;
		for (i = 0; i < k; i++)ca[i].money = -1;
		for (i = 0; i < n; i++)
		{
			cin >> x.name >> x.money;
			for (j = 0; j < k; j++)if (x.money > ca[j].money) { temp = ca[j]; ca[j] = x; x = temp; }
		}
		for (i = 0; i < k; i++)cout << ca[i].name << " " << ca[i].money << endl;
	}
	return 0;
}